<?php
// +-------------------------------------------------------------+
// | Tinysupe [ SIMPLE IS THE BEST ! ]
// +-------------------------------------------------------------+
// | Copyright (c) 2011 www.srccn.com All rights reserved.
// +-------------------------------------------------------------+
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +-------------------------------------------------------------+
// | Author: tinysu <tinysu@qq.com>
// +-------------------------------------------------------------+

class theme
{
	public $dir;
	private $dat, $tpl;

	function __construct(){
		$this->dir = 'themes/default';
		$this->dat = array();
		$this->tpl = null;
	}
	
	public function assign($key, $val=''){
		if(is_array($key)){
			foreach($key as $k => $v)
				$this->dat[$val.$k] = $v;
		}else{
			$this->dat[$key] = $val;
		}
	}
	
	public function exists($tpl){
		$this->tpl = $this->dir.'/'.$tpl.'.tpl.php';
		return is_file($this->tpl);
	}
	
	public function display($tpl){
		@header('Content-type:text/html; charset=utf-8');
		if($this->exists($tpl)){
			extract($this->dat); require($this->tpl);
		}else{
			echo('Cannot find '. $this->tpl);
		}
	}

	public function obtain($key){
		if(isset($this->dat[$key])){
			return $this->dat[$key];
		}
		return false;
	}
	
	function __destruct(){
		unset($this->dat);
	}
}
?>
